package com.mycompany.rest.controller;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.annotation.Resource;
import javax.imageio.ImageIO;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mycompany.rest.domain.Reserva;
import com.mycompany.rest.domain.ReservaList;
import com.mycompany.rest.service.ReservaService;

@Controller
public class ReservaController {

	protected static Logger logger = Logger.getLogger("controller");
	
	@Resource(name = "reservaService")
	private ReservaService reservaService;


	@RequestMapping(value = "/reserva/{id}", method = RequestMethod.GET, headers = "Accept=application/xml, application/json")
	public @ResponseBody Reserva getReserva(@PathVariable("id") Long id) {
		logger.debug("Provider has received request to get person with id: "
				+ id);

		// Call service here
		return reservaService.get(id);
	}

	@RequestMapping(value = "/reserva/{id}", method = RequestMethod.GET, headers = "Accept=application/html, application/xhtml+xml")
	public String getDestinoHTML(@PathVariable("id") Long id, Model model) {
		logger.debug("Provider has received request to get person with id: "
				+ id);

		// Call service to here
		model.addAttribute("reserva", reservaService.get(id));

		// This will resolve to /WEB-INF/jsp/getpage.jsp
		return "reserva_get";
	}

	@RequestMapping(value = "/reservas", method = RequestMethod.GET, headers = "Accept=application/xml, application/json")
	public @ResponseBody ReservaList getDestino() {
		logger.debug("Provider has received request to get all persons");

		// Call service here
		ReservaList result = new ReservaList();
		
		result.setData(reservaService.getAll());

		return result;
	}
	
}
